/*
 * Copyright 2000 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _WT_SESSION_H
#define _WT_SESSION_H

#include <tcl.h>

typedef struct WtSessionT
{
  int isInitialized;
  Tcl_Obj *clientValue;
  Tcl_Obj *clientId;
  time_t clientTimeStamp;
  Tcl_Obj *cookieName;
  Tcl_Obj *cookie;
  Tcl_Obj *cookieSendMode;
  int autoSweep;
  int maxIdleTime;
  double sweepFrequency;
  Tcl_Obj *handler;
  Tcl_Obj *handlerType;
  int handlerLoaded;
  Tcl_Obj *dbSession;
  Tcl_Obj *inProcSession;
} WtSession;

void WtInitSession(WtSession *s);
void WtDeleteSession(WtSession *s);
Tcl_Obj *WtGetInitialSessionId(WtSession *s, int *isAutoIdPtr,
  Tcl_Interp *interp);
Tcl_Obj *WtGetClientSessionId(WtSession *s, Tcl_Interp *interp);
Tcl_Obj *WtGenerateSessionId(WtSession *s, Tcl_Interp *interp);
void WtSessionAddEnvironment(Tcl_Obj *str);
Tcl_Obj *WtGetSessionCookie(WtSession *s, Tcl_Interp *interp);
int WtSetSessionCookieName(WtSession *s, Tcl_Obj *name, Tcl_Interp *interp);
int WtSetSessionCookie(WtSession *s, Tcl_Obj *id, Tcl_Interp *interp,
  time_t timeStamp);
int WtSetSessionHandler(WtSession *s, Tcl_Obj *handler, Tcl_Interp *interp);
int WtLoadSessionHandler(WtSession *s, Tcl_Interp *interp);
int WtUnloadSessionHandler(WtSession *s, Tcl_Interp *interp);
int WtShouldSweepSessions(WtSession *s, Tcl_Interp *interp);
int WtSessionEndRequest(WtSession *s, Tcl_Interp *interp);
int WtUnloadSession(WtSession *s, Tcl_Interp *interp);
int WtSessionCmd(ClientData clientData, Tcl_Interp *interp,
  int objc, Tcl_Obj *const objv[]);
int WtSessionClientIdCmd(ClientData clientData, Tcl_Interp *interp,
  WtSession *s, int objc, Tcl_Obj *const objv[]);
int WtSessionNewIdCmd(ClientData clientData, Tcl_Interp *interp,
  WtSession *s, int objc, Tcl_Obj *const objv[]);
int WtSessionCookieNameCmd(ClientData clientData, Tcl_Interp *interp,
  WtSession *s, int objc, Tcl_Obj *const objv[]);
int WtSessionCookieCmd(ClientData clientData, Tcl_Interp *interp,
  WtSession *s, int objc, Tcl_Obj *const objv[]);
int WtSessionCookieSendModeCmd(ClientData clientData, Tcl_Interp *interp,
  WtSession *s, int objc, Tcl_Obj *const objv[]);
int WtSessionMaxIdleTimeCmd(ClientData clientData, Tcl_Interp *interp,
  WtSession *s, int objc, Tcl_Obj *const objv[]);
int WtSessionSweepFrequencyCmd(ClientData clientData, Tcl_Interp *interp,
  WtSession *s, int objc, Tcl_Obj *const objv[]);
int WtSessionHandlerCmd(ClientData clientData, Tcl_Interp *interp,
  WtSession *s, int objc, Tcl_Obj *const objv[]);
int WtSessionHandlerTypeCmd(ClientData clientData, Tcl_Interp *interp,
  WtSession *s, int objc, Tcl_Obj *const objv[]);
WtSession *WtGetAssocSession(Tcl_Interp *interp);
void WtInitSessionCommands(Tcl_Interp *interp);
int WtSessionHandler(WtSession *s, Tcl_Obj *handler,
  Tcl_Obj *method, Tcl_Interp *interp, int objc,
  Tcl_Obj *const objv[]);
WtSession *WtGetAssocSession(Tcl_Interp *interp);
int WtSessionCmd(ClientData clientData, Tcl_Interp *interp,
  int objc, Tcl_Obj *const objv[]);
int WtSessionHandlerStr(WtSession *s, Tcl_Obj *handler,
  const char *methodStr, Tcl_Interp *interp, int objc,
  Tcl_Obj *const objv[]);
int WtSessionHandlerInternal(WtSession *s,
  Tcl_Obj *handler, Tcl_Obj *method, Tcl_Interp *interp,
  int objc, Tcl_Obj *const objv[]);
int WtPrepareSessionHandler(WtSession *s, Tcl_Obj *method,
  Tcl_Interp *interp);
void WtSessionCmdUsage(Tcl_Interp *interp, Tcl_Obj *cmd);

#endif /* !_WT_SESSION_H */
